package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.GradeUS;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface GradeUSMapper {
    @Delete({
        "delete from grade_u_s",
        "where gId = #{gid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer gid);

    @Insert({
        "insert into grade_u_s (gId, shopId, ",
        "uId, grade)",
        "values (#{gid,jdbcType=INTEGER}, #{shopid,jdbcType=INTEGER}, ",
        "#{uid,jdbcType=INTEGER}, #{grade,jdbcType=DOUBLE})"
    })
    int insert(GradeUS record);

    @Select({
        "select",
        "gId, shopId, uId, grade",
        "from grade_u_s",
        "where gId = #{gid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="gId", property="gid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER),
        @Result(column="uId", property="uid", jdbcType=JdbcType.INTEGER),
        @Result(column="grade", property="grade", jdbcType=JdbcType.DOUBLE)
    })
    GradeUS selectByPrimaryKey(Integer gid);

    @Select({
        "select",
        "gId, shopId, uId, grade",
        "from grade_u_s"
    })
    @Results(id = "gradeMap",value = {
        @Result(column="gId", property="gid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER),
        @Result(column="uId", property="uid", jdbcType=JdbcType.INTEGER),
        @Result(column="grade", property="grade", jdbcType=JdbcType.DOUBLE)
    })
    List<GradeUS> selectAll();

    /*通过uId,shopId获取评分*/
    @Select("select * from grade_u_s where uId=#{uId} and shopId=#{shopId}")
    @ResultMap("gradeMap")
    GradeUS selectByUId(@Param("uId")Integer uId,@Param("shopId")Integer shopId);

    @Update({
        "update grade_u_s",
        "set shopId = #{shopid,jdbcType=INTEGER},",
          "uId = #{uid,jdbcType=INTEGER},",
          "grade = #{grade,jdbcType=DOUBLE}",
        "where gId = #{gid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(GradeUS record);
}